package club.jdiy.core.convert;

import club.jdiy.utils.DateUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

class DateConverter extends Converter {
    private final Date source;

    public DateConverter(Date source) {
        this.source = source;
    }

    @Override
    public Date getSource() {
        return source;
    }

    @Override
    public Long getLong() {
        return source.getTime();
    }


    @Override
    public String getString() {
        return DateUtils.fmt_datetime.format(getLocalDateTime());
    }

    @Override
    public Date getDate() {
        return source;
    }

    @Override
    public LocalDate getLocalDate() {
        return source.toInstant().atOffset(ZoneOffset.ofHours(8)).toLocalDate();
    }

    @Override
    public LocalDateTime getLocalDateTime() {
        return source.toInstant().atOffset(ZoneOffset.ofHours(8)).toLocalDateTime();
    }

}
